package com.java.dormitorymanager.mvc.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @program: DormitoryManager
 * @description: 显示错误信息
 * @author: ShuangChenYue
 * @create: 2021-05-16 16:17
 **/
@WebServlet(value = "/ViewExceptionPage")
public class ViewExceptionPageServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("你错了");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        String alert = (String) req.getAttribute("alert");
        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>错误信息</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-manager/exceptionPage.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Alert</h1>");
        out.println("<h1 id=\"h02\">"+alert+"</h1>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
